﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;

namespace sp500
{
    class CSVSaverLoader
    {
        string mfilename;
        string mpath;

        public CSVSaverLoader(string filename)
        {
            mfilename = filename;
            string defaultdirectory = @"D:\sp500\";
            string postflix = ".csv";
            mpath = defaultdirectory + filename + postflix;
        }

        public void savefile2csv(string csvdata)
        {
            try
            {
	            using(StreamWriter sw = File.CreateText(mpath))
	            {
	                sw.Write(csvdata);
	            }
            }
            catch (System.Exception ex)
            {
            	MessageBox.Show(ex.Message);
            }
        }

        public string readcsvffile()
        {
            string reStr;
            using(StreamReader sr = File.OpenText(mpath))
            {
                reStr = sr.ReadToEnd();
            }
            
            return reStr;
        }
    }
}
